#!/bin/bash                                                                                                                          

if [ -z "$1" ]
then
        BRANCH='master'
else
        BRANCH=$1
fi
WORK_DIR=$(cd "$(dirname $0)";pwd)
COMPILE_DIR=${WORK_DIR}/compile
PACKAGES_DIR=${COMPILE_DIR}/packages
REPORT_DIR=${COMPILE_DIR}/report
commit_id=`docker exec -it  llvm-build /bin/bash -c "cd /srv/workspace/llvm-release/${BRANCH}/toolchain/llvm-project && git rev-parse --short HEAD"`
commit_id=$(echo $commit_id | sed 's/\r//g')
commit_id=$(echo ${commit_id:0:6})
date="20250320"

rm -rf ${PACKAGES_DIR}
mkdir -p ${PACKAGES_DIR}
rm -rf ${REPORT_DIR}/${date}-${commit_id}
mkdir -p ${REPORT_DIR}/${date}-${commit_id}

cp /data/bisheng/llvm-release/${BRANCH}/packages/target_location/clang* ${PACKAGES_DIR}
cd ${PACKAGES_DIR}

for file in *.tar.gz; do
    tar -xmf "$file"
done

cd ${REPORT_DIR}/${date}-${commit_id}

python3 ${WORK_DIR}/file_integrity_check/file_permission_check.py --compare-between-path ${WORK_DIR}/old-sdk/clang_darwin-arm64-829e8c-20250220 ${PACKAGES_DIR}/clang_darwin-arm64-${commit_id}-${date}
sleep 2
python3 ${WORK_DIR}/file_integrity_check/file_permission_check.py --compare-between-path ${WORK_DIR}/old-sdk/clang_darwin-x86_64-829e8c-20250220 ${PACKAGES_DIR}/clang_darwin-x86_64-${commit_id}-${date}
sleep 2
python3 ${WORK_DIR}/file_integrity_check/file_permission_check.py --compare-between-path ${WORK_DIR}/old-sdk/clang_linux-x86_64-829e8c-20250220 ${PACKAGES_DIR}/clang_linux-x86_64-${commit_id}-${date}
sleep 2
python3 ${WORK_DIR}/file_integrity_check/file_permission_check.py --compare-between-path ${WORK_DIR}/old-sdk/clang_linux_aarch64-829e8c-20250220 ${PACKAGES_DIR}/clang_linux_aarch64-${commit_id}-${date}
sleep 2
python3 ${WORK_DIR}/file_integrity_check/file_permission_check.py --compare-between-path ${WORK_DIR}/old-sdk/clang_ohos-arm64-829e8c-20250220 ${PACKAGES_DIR}/clang_ohos-arm64-${commit_id}-${date}
sleep 2
python3 ${WORK_DIR}/file_integrity_check/file_permission_check.py --compare-between-path ${WORK_DIR}/old-sdk/clang_windows-x86_64-829e8c-20250220 ${PACKAGES_DIR}/clang_windows-x86_64-${commit_id}-${date}
cd -
